import { createRouter, createWebHashHistory } from 'vue-router'
// 引入本地图片方法
import { imgLocalUrl } from '@/utils/imgLocalUrl'

const LayOut = () => import('@/layout/index.vue')
export const routesMap = [
  {
    path: '/',
    name: 'Goods',
    component: LayOut,
    children: [
      {
        path: '/',
        name: 'GoodsIndex',
        meta: {
          title: '库存',
          icon: imgLocalUrl('@/assets/layout/goods.png')
        },
        component: () => import('@/views/goods/index.vue')
      }
    ]
  },
  {
    path: '/orders',
    name: 'Orders',
    component: LayOut,
    children: [
      {
        path: '/orders',
        name: 'OrdersIndex',
        meta: {
          title: '订单',
          icon: imgLocalUrl('@/assets/layout/orders.png')
        },
        component: () => import('@/views/orders/index.vue')
      }
    ]
  },
  {
    path: '/custom',
    name: 'Custom',
    component: LayOut,
    children: [
      {
        path: '/custom',
        name: 'CustomIndex',
        meta: {
          title: '客户',
          icon: imgLocalUrl('@/assets/layout/user.png')
        },
        component: () => import('@/views/custom/index.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: LayOut,
    children: [
      {
        path: '/login',
        name: 'Login',
        meta: {
          title: '设置',
          icon: imgLocalUrl('@/assets/layout/settings.png')
        },
        component: () => import('@/views/login/index.vue')
      }
    ]
  },
  {
    path: '/manage/:id',
    name: 'Manage',
    hidden: true,
    component: LayOut,
    children: [
      {
        path: '/manage/:id',
        name: 'ManageIndex',
        component: () => import('@/views/manage/index.vue')
      }
    ]
  }
]
export const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior: () => ({ left: 0, top: 0 }),
  routes: routesMap
})

export const setupRouter = (app) => {
  app.use(router)
}
